package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.GlobalClobsMapper;
import com.kaili.basic.pojo.dto.GlobalClobDto;
import com.kaili.basic.pojo.entity.GlobalClobEntity;
import com.kaili.basic.pojo.entity.StrategyMainEntity;
import com.kaili.basic.pojo.vo.GlobalClobVO;
import com.kaili.basic.service.IGlobalClobService;
import com.kaili.common.util.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 复选数据 service实现类
 * @author:zhangjl
 * @Time: 2019-07-24
 * @Copyright: ©  杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅,禁止外泄或用于其它商业目的
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class GlobalClobsServiceImpl extends ServiceImpl<GlobalClobsMapper, GlobalClobEntity> implements IGlobalClobService {

    @Override
    public boolean add(StrategyMainEntity entity) {
        List<GlobalClobEntity> list = entity.getGlobalClobEntityList();
        for (GlobalClobEntity clobEntity :list){
            clobEntity.setData_id(entity.getId());
        }
        this.insertBatch(list);

        return true;
    }

    @Override
    public boolean modify(StrategyMainEntity entity) {
        //1、删除设备策略
        this.del(entity.getId());
        //2、新增设备类
        this.add(entity);
        return true;
    }

    @Override
    public boolean del(Integer id) {
        Wrapper<GlobalClobEntity> wrapper = new EntityWrapper<>();
        wrapper.where("data_id={0}", id);
        this.delete(wrapper);
        return true;
    }

    @Override
    public List<GlobalClobVO> queryList(GlobalClobDto dto) {
        return baseMapper.queryList(ObjectUtils.objectToMap(dto));
    }

}
